package com.example.administrator.yuejian2.model;

import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.SharePictureBean;
import com.example.administrator.yuejian2.service.RetrofitService;
import com.example.administrator.yuejian2.service.SharePictureService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.administrator.yuejian2.other.Url.BASEURL;
import static com.example.administrator.yuejian2.other.Url.URL5;

public class SharePicModel {

    private Retrofit retrofit;
    private SharePictureService sharePictureService;

    public SharePicModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL+URL5)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        sharePictureService=retrofit.create(SharePictureService.class);
    }

    public void sharepicList(final RetrofitListener listener){
        Call<List<SharePictureBean>> call=sharePictureService.picturelist();
        call.enqueue(new Callback<List<SharePictureBean>>() {
            @Override
            public void onResponse(Call<List<SharePictureBean>> call, Response<List<SharePictureBean>> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<List<SharePictureBean>> call, Throwable t) {

            }
        });
    }

    public void sharepicDetail(String picture_id,final RetrofitListener listener){
        Call<SharePictureBean> call=sharePictureService.pictureDetail(picture_id);
        call.enqueue(new Callback<SharePictureBean>() {
            @Override
            public void onResponse(Call<SharePictureBean> call, Response<SharePictureBean> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<SharePictureBean> call, Throwable t) {

            }
        });
    }
}
